home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / The World of Computer Software.iso / coolcolr.zip / COOLCOLR.C < prev    next >
C/C++ Source or Header  |  1992-11-17  |  9KB  |  263 lines

  1. //****************************************************************************
  2. //      File:  COOLCOLR.C                                                  
  3. //                                                                         
  4. //   Purpose:  
  5. //                                                                         
  6. // Functions:  
  7. //             
  8. //                                                                         
  9. // Development Team:
  10. //
  11. //       Greg Keyser
  12. //
  13. // Written by Microsoft Product Support Services, Windows Developer Support
  14. // Copyright (c) 1992 Microsoft Corporation. All rights reserved.
  15. //****************************************************************************
  16.  
  17. #include <windows.h>
  18. #include <cpl.h>
  19. #include "commdlg.h"
  20. #include "global.h"
  21.  
  22. LONG FAR PASCAL CPlApplet(HWND, WORD, LONG, LONG);
  23. BOOL FAR PASCAL LibMain(HANDLE, WORD, WORD, LPSTR);
  24.  
  25. // we put LibMain and CPlApplet functions in the _INIT segment to make
  26. // the LibMain and CPlApplet discardable.
  27.  
  28. #pragma alloc_text( _INIT, LibMain, CPlApplet )
  29.  
  30. //****************************************************************************
  31. // Function: SaveToWinIni
  32. //
  33. // Purpose:  To save the new color settings to WIN.INI.  Rather than try to
  34. //           keep track of what's changed and what hasn't, I just get all
  35. //           the current system colors and write them out to WIN.INI.
  36. //           Simplicity prevails in this case.
  37. //
  38. // Parameters: None
  39. //
  40. // Returns : Nothing
  41. //
  42. // Comments:
  43. //
  44. // History:  Date       Author        Reason
  45. //           3/24/92    gak           Created
  46. //****************************************************************************
  47. void FAR PASCAL SaveToWinIni(void)
  48. {
  49.    char  *pszWinStrings[] = {
  50.                          "MenuText",
  51.                          "Menu",
  52.                          "TitleText",
  53.                          "ActiveTitle",
  54.                          "InactiveTitleText",
  55.                          "InactiveTitle",
  56.                          "WindowFrame",
  57.                          "InactiveBorder",
  58.                          "Scrollbar",
  59.                          "WindowText",
  60.                          "Window",
  61.                          "Background",
  62.                          "AppWorkspace",
  63.                          "ActiveBorder",
  64.                          "GrayText",
  65.                          "Hilight",
  66.                          "HilightText",
  67.                          "ButtonHilight",
  68.                          "ButtonShadow",
  69.                          "ButtonText",
  70.                          "ButtonFace"
  71.                         };
  72.  
  73.    char szColors[]="colors";
  74.    char szBuffer[128];
  75.  
  76.    BYTE Red, Green, Blue;
  77.    WORD wCtr;
  78.  
  79.    GetCurrentSysColors();
  80.  
  81.    for (wCtr=IDC_COLOR_MENUTEXT; wCtr<=IDC_COLOR_BTNFACE; wCtr++)
  82.       {
  83.          Red  =GetRValue(gdwOldSysColors[wCtr]);
  84.          Green=GetGValue(gdwOldSysColors[wCtr]);
  85.          Blue =GetBValue(gdwOldSysColors[wCtr]);
  86.          wsprintf(szBuffer, "%u %u %u", (WORD)(unsigned int)Red,
  87.                   (WORD)(unsigned int)Green, (WORD)(unsigned int)Blue);
  88.          WriteProfileString(szColors, pszWinStrings[wCtr], szBuffer);
  89.       }
  90.    
  91.    return;
  92. }
  93.  
  94. //****************************************************************************
  95. // Function: GetCurrentSysColors
  96. //
  97. // Purpose:  To initialize a global array that will be used if the user  
  98. //           CANCEL's his changes.
  99. //
  100. // Parameters: None
  101. //
  102. // Returns : Nothing
  103. //
  104. // Comments:
  105. //
  106. // History:  Date       Author        Reason
  107. //           3/23/92    gak           Created
  108. //****************************************************************************
  109. void FAR PASCAL GetCurrentSysColors(void)
  110. {
  111.    WORD wCtr;
  112.  
  113.    for (wCtr=IDC_COLOR_MENUTEXT; wCtr<=IDC_COLOR_BTNFACE; wCtr++)
  114.       gdwOldSysColors[wCtr]=GetSysColor(giSysColorArea[wCtr]);
  115.      
  116.    return;
  117. }
  118.  
  119. //****************************************************************************
  120. // Function: CPlApplet(HWND, WORD, LONG, LONG)
  121. //
  122. // Purpose:  The applets window procedure.  Called by Control Panel.     
  123. //
  124. // Parameters: None
  125. //         hCPlWnd == Handle to Control Panels window
  126. //             Msg == Current message 
  127. //         lParam1 == Varies depending on message 
  128. //         lParam2 == Varies depending on message 
  129. //
  130. // Returns : LONG, dependent on the message being processed.
  131. //
  132. // Comments: This function must be exported so CONTROL.EXE can do a 
  133. //           GetProcAddress() and ultimately send messages to this routine.
  134. //
  135. // History:  Date       Author        Reason
  136. //           3/23/92    gak           Created
  137. //****************************************************************************
  138. LONG FAR PASCAL CPlApplet(HWND hCPlWnd, WORD Msg, LONG lParam1, LONG lParam2)
  139. {
  140.  
  141. static char *szAppNames[]={"System Color Dropper"};
  142. static char *szDescriptions[]={"Set your system colors the cool way!"};
  143. static int icons[NUM_APPLETS] = { COOLCOLR_ICON };
  144.  
  145. int          i;
  146. LPNEWCPLINFO lpCPlInfo;
  147.  
  148.     switch (Msg) {
  149.  
  150.         case CPL_INIT:
  151.  
  152.             // first message to CPlApplet(), sent once only -
  153.             // returns a boolean for sucessful initialization
  154.  
  155.             GetCurrentSysColors();
  156.             ghWnd=hCPlWnd;
  157.             return (LONG)TRUE;
  158.  
  159.         case CPL_GETCOUNT:
  160.  
  161.             // second message to CPlApplet(), sent once only -
  162.             // return the number of applets supported by this DLL.
  163.  
  164.             return NUM_APPLETS;
  165.             break;
  166.  
  167.         case CPL_NEWINQUIRE:
  168.  
  169.             // third message to CPlApplet() - it is sent as many times
  170.             // as the number of applets returned by CPL_GETCOUNT message
  171.  
  172.             lpCPlInfo = (LPNEWCPLINFO)lParam2;
  173.  
  174.             // lParam1 is an index ranging from 0 to (NUM_APPLETS - 1) 
  175.  
  176.             i = (int)lParam1;
  177.  
  178.             // your DLL must contain an icon and two string resources -
  179.             // hIcon is the icon handle, szName and szInfo are 
  180.             // strings describing the applets name and description
  181.  
  182.             lpCPlInfo->dwSize        = (DWORD)sizeof(NEWCPLINFO);
  183.             lpCPlInfo->dwFlags       = (DWORD)NULL;
  184.             lpCPlInfo->dwHelpContext = (DWORD)NULL;
  185.             lpCPlInfo->lData         = NULL;
  186.             lpCPlInfo->hIcon         = LoadIcon(ghInst, MAKEINTRESOURCE(icons[i]));
  187.             lstrcpy(lpCPlInfo->szName, (LPSTR)szAppNames[i]);
  188.             lstrcpy(lpCPlInfo->szInfo, (LPSTR)szDescriptions[i]);
  189.             *(lpCPlInfo->szHelpFile) = NULL;
  190.             
  191.             break;
  192.  
  193.         case CPL_SELECT:
  194.  
  195.             // one of your applets has been selected
  196.             // lParam1 is an index from 0 to (NUM_APPLETS - 1)
  197.             // lParam2 is the lData value associated with the applet
  198.  
  199.             break;
  200.  
  201.         case CPL_DBLCLK:
  202.  
  203.             // one of your applets has been double-clicked
  204.             // lParam1 is an index from 0 to (NUM_APPLETS - 1)
  205.             // lParam2 is the lData value associated with the applet
  206.  
  207.             LaunchApplet();
  208.             break;
  209.  
  210.         case CPL_STOP:
  211.  
  212.             // sent once for each applet prior to the CPL_EXIT msg
  213.             // lParam1 is an index from 0 to (NUM_APPLETS - 1)
  214.             // lParam2 is the lData value associated with the applet
  215.  
  216.             if (glpColorsChunk)  //Clean up memory for colors dialog
  217.                {
  218.                   GlobalUnlock (ghColorsChunk);
  219.                   GlobalFree   (ghColorsChunk);
  220.                }
  221.  
  222.             break;
  223.  
  224.         case CPL_EXIT:
  225.  
  226.             // last message, sent once only, before CONTROL.EXE calls
  227.             // FreeLibrary() on your DLL.
  228.  
  229.             break;
  230.  
  231.         default:
  232.             break;
  233.     }
  234.  
  235.     return 0L;
  236. }
  237.  
  238. //****************************************************************************
  239. // Function: LibMain(HANDLE, WORD, WORD, LPSTR)
  240. //
  241. // Purpose:  To initialize a global array that will be used if the user  
  242. //           CANCEL's his changes.
  243. //
  244. // Parameters: None
  245. //       hInstance == Handle to this instance
  246. //        wDataSeg == Our data segment
  247. //       wHeapSize == Heap size from the .DEF file
  248. //       lpCmdLine == The command line
  249. //
  250. // Returns : Nothing
  251. //
  252. // Comments:
  253. //
  254. // History:  Date       Author        Reason
  255. //           3/23/92    gak           Created
  256. //****************************************************************************
  257. BOOL FAR PASCAL LibMain(HANDLE hInstance, WORD wDataSeg, WORD wHeapSize, LPSTR lpCmdLine)
  258. {
  259.     ghInst = hInstance;
  260.     return TRUE;
  261. }
  262.  
  263.